<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MediaSource extends Model
{
    use HasFactory;

    public $timestamps = null;

    protected $fillable = [
        'id',
        'name',
    ];

    public static function toOptions(): array
    {
        return MediaSource::query()
            ->get()
            ->pluck('name', 'id')
            ->toArray();
    }

    public static function toKeyOptions(): array
    {
        return MediaSource::query()
            ->select(['id'])
            ->get()
            ->pluck('id')
            ->toArray();
    }

    public static function initSource()
    {
        foreach (Clue::SOURCE_FIELDS as $key => $value) {
            self::updateOrCreate([
                'id' => $key,
                'name' => $value
            ]);
        }
    }

}
